package com.mytest.controller;

import com.mytest.pojo.Admin;
import com.mytest.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @BelongsProject: java-85-course-code
 * @BelongsPackage: com.mytest.controller
 * @Author: LiTongMiao
 * @Date: 2022/2/2 15:00
 * @Description: TODO
 */
//表明现在是控制器的对象，交给spring去创建对象
@Controller
@RequestMapping("/admin")
public class AdminAction {
    //切记：在所有的界面层，一定会有业务逻辑层的对象
    @Autowired
    AdminService adminService;

    //实现登录判断，并进行相应的跳转
    @RequestMapping("/login")
    public String login(String name, String pwd, HttpServletRequest request) {
        Admin admin = adminService.login(name, pwd);
        if (admin != null) {
            //登录成功
            return "main";
        } else {
            //登录失败
            request.setAttribute("errmsg","用户名或密码错误");
            return "login";
        }
    }
}
